package com.xiaoxu.intranetweb.mybatisplusSzappdb.controller.compete;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONObject;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.business.compete.ArchivedBu;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.dao.UserInfoDao;
import com.xiaoxu.intranetweb.util.PermissionCheck;
import com.xiaoxu.intranetweb.util.SzResult;
import com.xiaoxu.intranetweb.util.WebFunctionUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping(value = "/archived")
public class ArchivedController {
    @Autowired
    private ArchivedBu archivedBu;
    @Autowired
    private UserInfoDao userInfoDao;
    @Autowired
    private WebFunctionUtil webFunctionUtil;

    //更新归档状态控制层
    @PostMapping("/updateArchived")
    @PermissionCheck("archived_updateArchived")
    public SzResult updateArchived(@RequestBody JSONObject jsonObject, HttpServletRequest request) throws Exception {
        String id = jsonObject.getString("id");
        String archived = jsonObject.getString("archived");
        String token = request.getHeader("Authorization");      String plantId = request.getHeader("Plant-Id");
        return  archivedBu.updateCompeteArchived(id, archived, token,plantId);
    }
    //    一键归档功能，归档已经完成最后审批的竞价数据STATUS大于51，且是一个月以前发布的数据CREATE_DATE，默认为31天之前，根据
//    public SzResult updateCompeteArchivedAll(String token, String plantId) throws Exception {
    @PostMapping("/updateCompeteArchivedAll")
    @PermissionCheck("archived_updateArchived")
    public SzResult updateCompeteArchivedAll(HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        return  archivedBu.updateCompeteArchivedAll(token, plantId);
    }
}
